clc
clear
close all
%被测信号频率
f1 = 99000
f2 = 2000
f3 = 91000
% 点数
N = 1024
% 采样率
%  Fs = 10*2.56

Fs = 750000;
% Fs = f1*N/2
%  Fs = N*f1/20
%采样间隔时间
T = 1/Fs
%分辨率
Fbl = Fs/N
%设置采样 采样总时间：N*Ts  采N个点
x = linspace(0,N*T,N);
%进行采样
% y = 2.5*sin(2*pi*f1*x)+2.5*sin(2*pi*f2*x)+10;
%  y = sin(2*pi*f1*x)+sin(2*pi*f2*x);
y = sin(2*pi*f1*x);
% y = sin(2*pi*f1*x)+sin(2*pi*f2*x)+sin(2*pi*f3*x);
% stem(x,y,'o');
figure
plot(x,y,'r');
% subplot(1,3,1);plot(x,y,'--r*');
%进行FFT
Y = fft(y);
% subplot(1,3,2);
%  plot(0:N-1,abs(Y))
%取单边图谱
P2 = abs(Y)/N*2;
P1 = P2(1:N/2+1);
% P1(1:1) = P1(1:1)/2;%直流部分不需要乘2
k = Fs/N*(0:(N/2));
%得到的横坐标为频点，纵坐标为幅度
% subplot(1,3,3);
figure
plot(k,P1)
